package org.example

import org.apache.spark.{SparkConf, SparkContext}

object scala03 {
  def main(args: Array[String]): Unit = {
    val inputFile = "D:\\Scala_project\\20220323\\demo08\\1.txt"
    val config = new SparkConf().setAppName("wordCount").setMaster("local")
    val sc = new SparkContext(config)
    val textFile = sc.textFile(inputFile)
    println("================textFile===================")
    val wordCount = textFile.flatMap(line => line.split(" "))
      .map(word => (word, 1)).reduceByKey((a, b) => a + b)
    wordCount.foreach(println)
  }

}
